<?php
/**
 * Provides network checks for monitoring purposes
 */
class BRail_Network_Check
{
    /**
     * Check if the HTTP port is available
     * @param string $host
     * @param int $port
     * @param int $timeout
     * @return bool|string True if successful, error string if not
     */
    public static function checkHttp($host, $port = 80, $timeout = 1)
    {
        $oldErrorLevel = error_reporting('E_NONE');
        $fp = fsockopen($host, $port, $errno, $errstr, $timeout);
        error_reporting($oldErrorLevel);
        if ($fp === false) {
            return $errstr . '(' . $errno . ')';
        } else {
            fclose($fp);
            return true;
        }
    }
}